﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.Geodatabase;

namespace PlanningGIS.ArcGIS
{
    /// <summary>
    /// 要素操作类
    /// </summary>
    public class FeatureHelper
    {
        #region 取值
        /// <summary>
        /// 获取属性值，获取时判断过字段是否存在，若批量获取时可以自己中Feature的get_Value取值
        /// </summary>
        /// <param name="featureBuffer">空间对象</param>
        /// <param name="fieldname">属性名称</param>
        /// <returns></returns>
        public static string GetValue(IFeatureBuffer featureBuffer, string fieldname)
        {
            if (featureBuffer == null || string.IsNullOrWhiteSpace(fieldname))
                return "";
            int index = featureBuffer.Fields.FindField(fieldname);
            if (index < 0) return "";
            object obj = featureBuffer.get_Value(index);
            return obj == null ? "" : obj.ToString();
        }
        /// <summary>
        /// 获取属性值，获取时判断过字段是否存在，若批量获取时可以自己中Feature的get_Value取值
        /// </summary>
        /// <param name="feature">空间对象</param>
        /// <param name="fieldname">属性名称</param>
        /// <returns></returns>
        public static string GetValue(IFeature feature, string fieldname)
        {
            if (feature == null || string.IsNullOrWhiteSpace(fieldname))
                return "";
            int index = feature.Fields.FindField(fieldname);
            if (index < 0) return "";
            object obj = feature.get_Value(index);
            return obj == null ? "" : obj.ToString();
        }
        #endregion
    }
}
